BEGIN{
	FS = ":";
	file = ARGV[1]".map"
}

$1 ~ /"image"/ {split($2, temp, "\"");image = temp[2]}

$1 ~ /"margin"/ {margin = 0 + $2}
$1 ~ /"spacing"/ {spacing = 0 + $2}

$1 ~ /"tileheight"/ {tileheight = 0 + $2}
$1 ~ /"tilewidth"/ {tilewidth = 0 + $2}

$1 ~ /"height"/ {height = 0 + $2}
$1 ~ /"width"/ {width = 0 + $2}

$1 ~ /"data"/ {
	$2 = substr($2, 2);
	n = split($2, data, ",");
}

END{
	print image > file
	print margin, spacing >> file
	print tileheight, tilewidth >> file
	print height, width >> file
	for (i = 1; i < n; i++) {
		printf "%2d ",0+data[i] >> file;
		if (i%width == 0)
			printf "\n" >> file;
	}
}
